<template>
  <rx-layout >
    <div slot="center" style>
      <rx-fit :isheader="isheader">
          <div slot="toolheader" foldbtn="false" border="false">
            <div class="table-operator">
              <a-button  type="primary" icon="plus" @click="add">{{$ti18('rxList.newBtn','新建')}}</a-button>

            </div>
            <span class="search-btn-box"  v-if="!isheader">
            <span class="search-btn" @click.stop="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
          </span>
          </div>
          <div  btnalign="right" slot="searchbar" v-if="fitSearch" @search="search" @cancel="cancel" @close="closeSearchbar">
            <a-form :layout="colLayout">
              <a-row :gutter="24">
                <a-col :span="colSpan">
             <a-form-item :label="i18n('form.typeCode','类型编码')">
                      <a-input :placeholder="i18n('form.typeCode','类型编码','input')" v-model="queryParam.Q_TYPE_CODE__S_EQ" />
                    </a-form-item>
                </a-col>
                <a-col :span="colSpan">
            <a-form-item :label="i18n('form.typeName','类型名称')">
                      <a-input :placeholder="i18n('form.typeName','类型名称','input')" v-model="queryParam.Q_TYPE_NAME__S_LK" />
                    </a-form-item>
                </a-col>
              </a-row>
          </a-form>
        </div>
        <rx-grid
          ref="table"
          bordered
          :multiSelect="true"
          :columns="columns"
          :defaultPageSize="10"
          url="/api-user/user/org/osInstType/query"
          :queryParam="queryParam"
          data-field="result.data"
          :pageSizeOptions="['10','30','40']"
          id-field="typeId"
          @selectChange="onSelectChange"
        >
         <span slot="typeName" slot-scope="{text}">
             {{$i18(text,"类型名称")}}
         </span>
          <span slot="enabled" slot-scope="{text}">
            <a-tag :color="typeMap[text].color">
              <span>{{ typeMap[text].text }}</span>
            </a-tag>
           </span>
          <span slot="isDefault" slot-scope="{text}">
            <a-tag :color="typeMap[text].color">
              <span>{{ typeMap[text].text }}</span>
            </a-tag>
           </span>
          <span slot="action" slot-scope="{ text, record }" class="actionIcons">
               <span   @click="edit(record)" v-if="record.isDefault=='N'">{{$ti18('rxList.editBtn','编辑')}}</span>
               <span   @click="delByIds([record.typeId])"  v-if="record.isDefault=='N'">{{$ti18('rxList.delBtn','删除')}}</span>
               <span  @click="assignMenu(record)" :title="i18n('list.assignMenu','菜单授权')">{{i18n('list.assignMenu','菜单授权')}}</span>
               <!--<span @click="assignApi(record)">接口授权</span>-->
          </span>
        </rx-grid>
      </rx-fit>
    </div>
  </rx-layout>
</template>

<script>
import OsInstTypeApi from '@/api/user/org/osInstType'
import OsInstTypeEdit from './OsInstTypeEdit'
import OsInstTypeMenuEdit from './OsInstTypeMenuEdit'
import OsInstTypeApiMenuEdit from "./OsInstTypeApiMenuEdit"
import { BaseList, RxLayout,Util,RxGrid,RxFit} from "@lowcode/jpaas-common-lib"
import OsGroupMenuEdit from "./OsGroupMenuEdit";
export default {
  name: 'OsInstTypeList',
  mixins: [BaseList],
  components: {
    OsInstTypeMenuEdit,
    OsInstTypeApiMenuEdit,
    RxLayout,
    RxGrid,
    RxFit
  },
  data() {
    return {
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        {
          title: this.i18n('form.typeCode','类型编码'),
          dataIndex: 'typeCode',
          width:120,
        },
        {
          title: this.i18n('form.typeName','类型名称'),
          dataIndex: 'typeName',
          scopedSlots: { customRender: 'typeName' },
          width:120,
        },
        {
          title: this.i18n('form.enabledOrNot','是否启用'),
          dataIndex: 'enabled',
          scopedSlots: { customRender: 'enabled' },
          width:60,
        },
        {
          title: this.i18n('form.isDefault','默认'),
          dataIndex: 'isDefault',
          scopedSlots: { customRender: 'isDefault' },
          width:60,
        },
        /*{
          title: this.i18n('form.homeUrl','首页URL'),
          dataIndex: 'homeUrl',
          width:60,
        },*/
        {
          title: this.i18n('form.descp','描述'),
          dataIndex: 'descp',
          width:120,
        },
          {title: this.$ti18('rxForm.createTime','创建时间'), dataIndex: 'createTime', sorter: true, sortField: 'CREATE_TIME_', width: 120},
        {
          title: this.$ti18('rxList.action','操作'),
          width:120,
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        }
      ],
      component: OsInstTypeEdit,
      comment: this.i18n('list.instType','租户类型'),
      widthHeight: ['800px', '600px'],
      typeMap: {
          Y: { color: 'green', text: this.i18n('isSysMap.yes','是') },
          N: { color: 'red', text: this.i18n('isSysMap.no','否') },
      },

    }
  },

  created() {
  },
  methods: {
      i18n(name,text,key){
          return this.$ti18(name,text,"osInstType",key);
      },
    //一开始调用数据
    getListByParams(parameter) {
      return OsInstTypeApi.query(parameter)
    },
    // 删除
    delById(ids) {
      return OsInstTypeApi.del({ ids: ids.join(',') })
    },
    assignMenu(record) {
      var conf= {
        curVm:this,
        data:{pkId:record.typeId},
        widthHeight:['900px', '550px'],
        component:OsInstTypeMenuEdit,
        title:this.$i18(record.typeName,"国际化租户类型")+this.i18n('list.assignMenu','菜单授权')
      };
      Util.open(conf,function(action){});
    },
    assignApi(record){
      var conf= {
        curVm:this,
        data:{pkId:record.typeId},
        widthHeight:['500px', '550px'],
        component:OsInstTypeApiMenuEdit,
        title:record.typeName+this.i18n('list.assignApi','接口授权')
      };
      Util.open(conf,function(action){});
    },
    search(){
        this.$refs.table.loadData();
      },
      cancel(){
        this.resetSearch();
      },
    closeSearchbar(){
      //关闭过滤弹窗；（点击X触发）
      this.fitSearch = false ;
    },
  },

  watch: {}
}
</script>
<style>
</style>
